﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;

[assembly: WebResource("MVCnExt.Web.UI.Ext.Scripts.resources.css.panel.css", "text/css", PerformSubstitution=true)]
namespace MVCnExt.Web.UI.Ext
{
    /// <summary>
    /// Panel is a contentContainer that has specific functionality and structural components that make it the perfect building block for application-oriented user interfaces.
    /// </summary>
    [Description("Panel is a contentContainer that has specific functionality and structural components that make it the perfect building block for application-oriented user interfaces.")]
    public class ExtPanel : ExtContainer
    {
        private String _shadow = null;

        public override List<ScriptReference> GetScriptReferences()
        {
            return base.GetScriptReferences();
        }

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.Panel";

            String[] properties = new String[]{
                "animCollapse", "autoLoad", "autoScroll", "baseCls", "bbar", "bodyBorder",
                "border", "bufferResizeMilliseconds", "buttonAlign", "buttons", "collapseFirst", 
                "collapsed", "collapsedCls", "collapsible", "draggable", "elements",
                "floating", "footer", "frame", "header", "headerAsText", "hideCollapseTool", 
                "iconCls", "keys", "maskDisabled", "minButtonWidth", "shadow", "shadowOffset",
                "shim", "tabTip", "title", "titleCollapse", "tools", "region", "name", "split",
                "bodyStyle", "text"
            };

            Type component = typeof(ExtPanel);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtJsPanel.{0}'", property));

                Object value = i.GetValue(this, null);

                ////get the default value
                //if (value == null)
                //{
                //    // Gets the attributes for the property.
                //    System.ComponentModel.AttributeCollection attributes =
                //       TypeDescriptor.GetProperties(this)[property].Attributes;

                //    /* get the default value by retrieving the DefaultValueAttribute 
                //       from the AttributeCollection. */
                //    DefaultValueAttribute defaultAttribute =
                //       (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];
                //    if (defaultAttribute != null)
                //        value = defaultAttribute.Value;
                //}
                
                if (value == null)
                {
                    continue;
                }

                if (!(value is String) && !(value is region))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

           
            //else if (html != null)
            //    desc.AddPropertyBase("contentEl", String.Format("'{0}'", GetControlID("Body")));

            //RegisterClientEvents(desc);

            return list;
        }

      
        #region Public Properties

        /// <summary>
        /// If the region is splited
        /// </summary>
        public bool? split { get; set; }

        public String margins { get; set; }

        public String cmargins { get; set; }

        public region? region { get; set; }

        public String name { get; set; }

        public String text { get; set; }

        public Boolean? animCollapse { get; set; }       

        public String autoLoad { get; set; }

        public Boolean? autoScroll { get; set; }

        public String baseCls { get; set; }

        public String bbar { get; set; }

        public Boolean? bodyBorder { get; set; }

        public String bodyStyle { get; set; }

        public Boolean? border { get; set; }

        public Int32? bufferResizeMilliseconds { get; set; }

        public align? buttonAlign { get; set; }

        public String buttons { get; set; }

        public Boolean? collapseFirst { get; set; }

        public Boolean? collapsed { get; set; }

        public String collapsedCls { get; set; }

        public Boolean? collapsible { get; set; }        

        public Boolean? draggable { get; set; }

        public String elements { get; set; }

        public Boolean? floating { get; set; }

        public Boolean? footer { get; set; }

        public Boolean? frame { get; set; }

        public Boolean? header { get; set; }

        public Boolean? headerAsText { get; set; }

        public Boolean? hideCollapseTool { get; set; }

        public String iconCls { get; set; }

        public String keys { get; set; }

        public Boolean? maskDisabled { get; set; }

        public Int32? minButtonWidth { get; set; }

        public Boolean? shadow { get; set; }

        //public String shadow
        //{
        //    get
        //    {
        //        return _shadow;
        //    }
        //    set
        //    {
        //        Boolean boolValue;
        //        if (!String.IsNullOrEmpty(value) && !Boolean.TryParse(value, out boolValue))
        //        {
        //            try
        //            {
        //                Enum.Parse(typeof(shadowMode), value, true);
        //            }
        //            catch (ArgumentException)
        //            {
        //                throw;
        //            }
        //        }
        //    }
        //}

        public Int32? shadowOffset { get; set; }

        public Boolean? shim { get; set; }

        public String tabTip { get; set; }

        //public String tbar { get; set; }

        public String title { get; set; }

        public Boolean? titleCollapse { get; set; }

        public String tools { get; set; }

        public override Unit? height { get; set; }

        public override Unit? width { get; set; }

        //public override String id { get; set; }

        #endregion

    }
}
